package com.yuncheng.spcyApi.spcy;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.yuncheng.entity.YcSysUser;
import com.yuncheng.vo.CurrentUserVo;
import com.yuncheng.vo.HttpResult;
import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.spcyApi.constant.common.BusinessConstant;
import com.yuncheng.spcyApi.constant.common.LogConstant;
import com.yuncheng.spcyApi.constant.common.SpcyCommonConstant;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.constant.flow.YpscFlowConstant;
import com.yuncheng.spcyApi.constant.jcy.JcydjbConstant;
import com.yuncheng.spcyApi.constant.other.ParamsConstant;
import com.yuncheng.spcyApi.constant.wjml.WjmlConstant;
import com.yuncheng.spcyApi.selectXzxkApi.api.XzspJkApi;
import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.bo.FlowDbrParamBo;
import com.yuncheng.spcyApi.busService.BusService;

import com.yuncheng.spcyApi.entity.*;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.spcyApi.flow.SpcyFlowConstant;
import com.yuncheng.spcyApi.flowService.*;
import com.yuncheng.spcyApi.mapper.SpcyRsHcyMapper;
import com.yuncheng.spcyApi.mapper.SpcySqsxBaiscMapper;
import com.yuncheng.spcyApi.service.*;
import com.yuncheng.spcyApi.spcyService.SpcyBlgcclService;
import com.yuncheng.spcyApi.spcyService.XpryTimedTasksService;
import com.yuncheng.spcyApi.utils.*;
import com.yuncheng.spcyApi.vo.common.PageVo;
import com.yuncheng.spcyApi.vo.common.Result;
import com.yuncheng.spcyApi.vo.jcy.HcyJbxxVo;
import com.yuncheng.spcyApi.vo.jcy.HcyXpVo;
import com.yuncheng.spcyApi.vo.jcy.RsHcyVo;
import com.yuncheng.spcyApi.vo.sqsx.SqsxWjmljlVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import utils.DateConversionUtils;
import utils.LogUtils;
import utils.ObjectToMapUtils;
import utils.PdfUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.stream.Collectors;

@Api(tags = "审评查验-通用方法接口")
@RestController
@RequestMapping("/api/spzx-spcy/common")
public class SpcyCommonController {
    private static final Logger log = LoggerFactory.getLogger(SpcyCommonController.class);

    @Resource
    private ISpcyRsJjrkService spcyRsJjrkService;

    @Resource
    private ISpcySqsxBaiscService spcySqsxBaiscService;

    @Resource
    private ISpcySqsxWjjlService spcySqsxWjjlService;

    @Resource
    private ISpcySqsxWjmlService spcySqsxWjmlService;

    @Resource
    private ISpcySqsxWjmljlService spcySqsxWjmljlService;

    @Resource
    private ISpcyRsGcyService spcyRsGcyService;

    @Resource
    private ISpcyRsHcyService spcyRsHcyService;

    @Resource
    private IYcSysUserService ycSysUserService;

    @Resource
    private ISpcySqsxXpjlService spcySqsxXpjlService;

    @Resource
    private ISpcySqsxJcxmService spcySqsxJcxmService;

    @Resource
    private XzspJkApi xzspJkApi;

    @Resource
    private LocalFileUploadUtils localFileUploadUtils;

    @Resource
    private BusService busService;

    @Resource
    private SpcyRsHcyMapper spcyRsHcyMapper;

    @Resource
    private SpcySqsxBaiscMapper spcySqsxBaiscMapper;

    @Resource
    private ISpcyLogService spcyLogService;

    @Resource
    private ISpcyRsParamsService spcyRsParamsService;

    @Resource
    @Lazy
    private YpscFlowService ypscFlowService;

    @Resource
    @Lazy
    private YpzcFlowService ypzcFlowService;

    @Resource
    @Lazy
    private YpltFlowService ypltFlowService;

    @Resource
    @Lazy
    private YlqxFlowService ylqxFlowService;

    @Resource
    @Lazy
    private HzpFlowService hzpFlowService;

    @Resource
    @Lazy
    private YpzclcFlowService ypzclcFlowService;

    @Resource
    @Lazy
    private SpcyBlgcclService spcyBlgcclService;

    @Resource
    private ISpcySqsxXptjjlService spcySqsxXptjjlService;

    @Resource
    private XpryTimedTasksService xpryTimedTasksService;

    @Log(title = "没有初始化的申请事项")
    @ApiOperation(value = "没有初始化的申请事项")
    @GetMapping(value = "noInitSqsxBaisc")
    public HttpResult<?> noInitSqsxBaisc(SpcySqsxBasic sqsx,
                                         @RequestParam(name = "isSelectNotInit",defaultValue = "true") boolean isSelectNotInit,
                                         @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){
        Page<SpcySqsxBasic> page = new Page<>(pageNo,pageSize);
        /*LambdaQueryWrapper<SpcySqsxBasic> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(sqsx.getFywflcode()),SpcySqsxBasic::getFywflcode, sqsx.getFywflcode());
        queryWrapper.eq(StringUtils.isNotBlank(sqsx.getFsxmc()),SpcySqsxBasic::getFsxmc, sqsx.getFsxmc());
        queryWrapper.eq(StringUtils.isNotBlank(sqsx.getFqymc()),SpcySqsxBasic::getFqymc, sqsx.getFqymc());
        queryWrapper.eq(StringUtils.isNotBlank(sqsx.getFsqdbh()),SpcySqsxBasic::getFsqdbh, sqsx.getFsqdbh());
        queryWrapper.eq(StringUtils.isNotBlank(sqsx.getFslbh()),SpcySqsxBasic::getFslbh, sqsx.getFslbh());

        IPage<SpcySqsxBasic> basicPage = spcySqsxBaiscService.page(page, queryWrapper);*/
        IPage<SpcySqsxBasic> basicPage = spcySqsxBaiscMapper.selectNoInitSqsxBaisc(page, sqsx, isSelectNotInit);

        return HttpResult.ok(basicPage);
    }

    @Log(title = "删除没有初始化的申请事项")
    @ApiOperation(value = "删除没有初始化的申请事项")
    @DeleteMapping(value = "deleteNoInitSqsx")
    public HttpResult<?> deleteNoInitSqsx(@RequestParam("ids") String ids){
        if (StringUtils.isBlank(ids)){
            return HttpResult.error("参数不能为空");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcySqsxBasic> sqsxBasicList = spcySqsxBaiscService.listByIds(idsList);
        String log = "";
        for (SpcySqsxBasic basic : sqsxBasicList){
            boolean flag = spcySqsxBaiscService.removeById(basic.getId());
            if (flag) {
                // 将map里面的属性和值转String
                Map<String, Object> beanMap = ObjectToMapUtils.objectToMap(basic);
                log += LogUtils.MapToStringMethod(beanMap);
                spcyLogService.addLogs("删除申请事项", log, basic.getId(), SpcyConstant.LOGS_SYS_TYPE_SC, SpcyConstant.LOGS_SYS_TYPE_SC);
                log = "";
            }
        }
        return HttpResult.ok("删除成功");
    }

    @Log(title = "初始化申请事项-流程")
    @ApiOperation(value = "初始化申请事项-流程")
    @GetMapping(value = "initSqsxJob")
    public HttpResult<?> initSqsxJob(@RequestParam("ids") String ids){
        if (StringUtils.isBlank(ids)){
            return HttpResult.error("参数丢失，请联系管理员");
        }
        CurrentUserVo currentUser = GetCurrentUserUtils.getCurrentUser();
        if (currentUser == null){
            return HttpResult.error("当前登录已失效，请重新登录");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));

        String fywflcode = "";
        for (String id : idsList) {
            SpcySqsxBasic basic = spcySqsxBaiscService.selectSqsxById(id);
            if (basic != null) {
                fywflcode = basic.getFywflcode();
            }

            if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPSC)) {
                // 药品生产
                Result result = ypscFlowService.initJob(id, currentUser);
                if (!result.isSuccess()) {
                    return HttpResult.error(result.getMessage());
                }
            } else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPZC)) {
                // 药品注册
                Result result = ypzcFlowService.initJob(id, currentUser);
                if (!result.isSuccess()) {
                    return HttpResult.error(result.getMessage());
                }
            } else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPJY)) {
                // 药品流通
                Result result = ypltFlowService.initJob(id, currentUser);
                if (!result.isSuccess()) {
                    return HttpResult.error(result.getMessage());
                }
            } else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YLQX)) {
                // 医疗器械
                Result result = ylqxFlowService.initJob(id, currentUser);
                if (!result.isSuccess()) {
                    return HttpResult.error(result.getMessage());
                }
            } else if (fywflcode.equals(SpcyConstant.YWFL_CODE_HZP)) {
                // 化妆品
                Result result = hzpFlowService.initJob(id, currentUser);
                if (!result.isSuccess()) {
                    return HttpResult.error(result.getMessage());
                }
            } else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPZCLC)) {
                // 药品注册 - 临床
                Result result = ypzclcFlowService.initJob(id, currentUser);
                if (!result.isSuccess()) {
                    return HttpResult.error(result.getMessage());
                }
            } else {
                log.error("不存在该业务分类: {}", fywflcode);
            }
        }

        return HttpResult.ok("初始化成功");
    }


    /** -----------------------【 新增、复制、计算日期、保存、获取行政审批 - 功能 】-------------------------- */

    /**
     * 新增申请事项
     */
    @Log(title = "新增申请事项")
    @ApiOperation(value = "新增申请事项")
    @ApiImplicitParam(name = "fywflcode",value = "业务分类编码",required = true)
    @GetMapping(value = "addSqsxBasic")
    public HttpResult<?> addSqsxBasic(@RequestParam(value = "fywflcode",defaultValue = "")String fywflcode,
                                      @RequestParam(value = "hjmc",defaultValue = "")String hjmc){
        if (StringUtils.isBlank(fywflcode)){
            return HttpResult.error("业务分类编码不能为空");
        }
        SpcySqsxBasic basic = new SpcySqsxBasic();
        basic.setId(GetUuIdUtils.ReplaceUuId());
        basic.setFywflcode(fywflcode);
        basic.setFsxsqjbxxid(GetUuIdUtils.ReplaceUuId());
        if (StringUtils.isNotBlank(fywflcode) && fywflcode.equals(SpcyConstant.YWFL_CODE_YLQX)){
            basic.setFscms(SpcyConstant.SQSX_SCMS_SCJCANBJSSC);
            basic.setFsplx(SpcyConstant.Sp_type_Ns); // 默认内审

        }else if (StringUtils.isNotBlank(fywflcode) && fywflcode.equals(SpcyConstant.YWFL_CODE_YPZC)){
            basic.setFscms(SpcyConstant.SQSX_SCMS_SCJCANBJSSC);
            basic.setFsplx(SpcyConstant.Sp_type_Ns); // 默认内审

        }else if (StringUtils.isNotBlank(fywflcode) && fywflcode.equals(SpcyConstant.YWFL_CODE_HZP)){
            basic.setFscms(SpcyConstant.SQSX_SCMS_SCJCANBJSSC);
            basic.setFsplx(SpcyConstant.Sp_type_Ns); // 默认内审

        }else if (StringUtils.isNotBlank(fywflcode) && fywflcode.equals(SpcyConstant.YWFL_CODE_YPZCLC)){
            basic.setFscms(SpcyConstant.SQSX_SCMS_SCJCANBJSSC);
            basic.setFsplx(SpcyConstant.Sp_type_Ns); // 默认内审

        }

        basic.setFsyts("0");
        spcySqsxBaiscService.save(basic);
        SpcySqsxJob job = null;
        CurrentUserVo currentUser = GetCurrentUserUtils.getCurrentUser();
        if (currentUser == null){
            return HttpResult.error("登录失效，请重新登录");
        }
        if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPSC)){
            // 药品生产
            Result result = ypscFlowService.initJob(basic.getId(), currentUser);
            if (!result.isSuccess()){
                return HttpResult.error(result.getMessage());
            }else {
                job = (SpcySqsxJob) result.getResult();
            }
        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPZC)){
            if (StringUtils.isNotBlank(hjmc)){
                Result result = ypzcFlowService.initJob(basic.getId(),hjmc,currentUser);
                if (!result.isSuccess()) {
                    return HttpResult.error(result.getMessage());
                } else {
                    job = (SpcySqsxJob) result.getResult();
                }
            }else {
                // 药品注册
                Result result = ypzcFlowService.initJob(basic.getId(), currentUser);
                if (!result.isSuccess()) {
                    return HttpResult.error(result.getMessage());
                } else {
                    job = (SpcySqsxJob) result.getResult();
                }
            }
        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPJY)){
            // 药品流通
            Result result = ypltFlowService.initJob(basic.getId(), currentUser);
            if (!result.isSuccess()){
                return HttpResult.error(result.getMessage());
            }else {
                job = (SpcySqsxJob) result.getResult();
            }
        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YLQX)){
            // 医疗器械
            Result result = ylqxFlowService.initJob(basic.getId(), currentUser);
            if (!result.isSuccess()){
                return HttpResult.error(result.getMessage());
            }else {
                job = (SpcySqsxJob) result.getResult();
            }
        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_HZP)){
            // 化妆品
            Result result = hzpFlowService.initJob(basic.getId(), currentUser);
            if (!result.isSuccess()){
                return HttpResult.error(result.getMessage());
            }else {
                job = (SpcySqsxJob) result.getResult();
            }
        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPZCLC)){
            // 药品注册
            Result result = ypzclcFlowService.initJob(basic.getId(), currentUser);
            if (!result.isSuccess()){
                return HttpResult.error(result.getMessage());
            }else {
                job = (SpcySqsxJob) result.getResult();
            }
        }else {
            log.error("不存在该业务分类: {}",fywflcode);
        }

        Map map = new HashMap();
        map.put("sqsx",basic);
        map.put("job",job);

        if (StringUtils.isNotBlank(hjmc)){
            Map firstNodeDbr = busService.getZdFirstNodeDbr(fywflcode,hjmc);
            map.putAll(firstNodeDbr);
        }else {
            Map firstNodeDbr = busService.getFirstNodeDbr(fywflcode);
            map.putAll(firstNodeDbr);
        }

        return HttpResult.ok(map);
    }

    /**
     * 复制申请事项基本信息
     */
    @Log(title = "复制申请事项基本信息")
    @ApiOperation(value = "复制申请事项基本信息")
    @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true)
    @GetMapping(value = "copySqsxJbxx")
    public HttpResult<?> copySqsxJbxx(@RequestParam("sqsxid")String sqsxid,
                                  @RequestParam(value = "number",defaultValue = "1")String number){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项不能为空");
        }
        CurrentUserVo currentUser = GetCurrentUserUtils.getCurrentUser();
        if (currentUser == null){
            return HttpResult.error("登录过期，请重新登录");
        }

        String fywflcode = "";
        SpcySqsxBasic basic = spcySqsxBaiscService.getById(sqsxid);
        if (basic != null){
            fywflcode = basic.getFywflcode();
        }
        SpcySqsxBasic newBasic = null;
        Integer fzsl = Integer.valueOf(number);
        for (int i=0; i<fzsl; i++){
            // 获取需要复制的字段
            List<SpcyRsParams> fzParamsList = spcyRsParamsService.list(new LambdaQueryWrapper<SpcyRsParams>()
                    .eq(SpcyRsParams::getFywflcode, fywflcode)
                    .eq(SpcyRsParams::getFkey, ParamsConstant.sqsxjbxx_key)
                    .orderByAsc(SpcyRsParams::getFxh));
            List<String> keys = new ArrayList<>();
            if (CollectionUtils.isNotEmpty(fzParamsList)) {
                String fvalue = fzParamsList.get(0).getFvalue();
                keys = Arrays.asList(fvalue.split(","));
            }

            newBasic = ObjectCopyUtils.cloneObj(basic, SpcySqsxBasic.class, keys); // 复制对应的字段
            if (newBasic != null) {
                newBasic.setId(GetUuIdUtils.ReplaceUuId());
                if (StringUtils.isNotBlank(fywflcode) && fywflcode.equals(SpcyConstant.YWFL_CODE_YLQX)){
                    newBasic.setFscms(SpcyConstant.SQSX_SCMS_SCJCANBJSSC);
                    newBasic.setFsplx(SpcyConstant.Sp_type_Ns); // 默认内审
                }else if (StringUtils.isNotBlank(fywflcode) && fywflcode.equals(SpcyConstant.YWFL_CODE_YPZC)){
                    newBasic.setFscms(SpcyConstant.SQSX_SCMS_SCJCANBJSSC);
                    newBasic.setFsplx(SpcyConstant.Sp_type_Ns); // 默认内审
                }else if (StringUtils.isNotBlank(fywflcode) && fywflcode.equals(SpcyConstant.YWFL_CODE_HZP)){
                    newBasic.setFscms(SpcyConstant.SQSX_SCMS_SCJCANBJSSC);
                    newBasic.setFsplx(SpcyConstant.Sp_type_Ns); // 默认内审
                }else if (StringUtils.isNotBlank(fywflcode) && fywflcode.equals(SpcyConstant.YWFL_CODE_YPSC)){
                    newBasic.setFscms(SpcyConstant.SQSX_SCMS_XCJC);
                }else if (StringUtils.isNotBlank(fywflcode) && fywflcode.equals(SpcyConstant.YWFL_CODE_YPJY)){
                    newBasic.setFscms(SpcyConstant.SQSX_SCMS_XCJC);
                }else if (StringUtils.isNotBlank(fywflcode) && fywflcode.equals(SpcyConstant.YWFL_CODE_YPZCLC)){
                    newBasic.setFscms(SpcyConstant.SQSX_SCMS_SCJCANBJSSC);
                    newBasic.setFsplx(SpcyConstant.Sp_type_Ns); // 默认内审
                }
                spcySqsxBaiscService.save(newBasic);

                String logFz = "复制事项：";
                Map<String, Object> map = ObjectToMapUtils.objectToMap(newBasic);
                logFz += LogUtils.MapToStringMethod(map);
                spcyLogService.addLogs(YpscFlowConstant.HJMC_RWSL, logFz, sqsxid, LogConstant.LOGS_SQSX_BASIC, SpcyConstant.LOGS_SYS_TYPE_XZ);
            }

            if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPSC)){
                // 药品生产
                Result result = ypscFlowService.initJob(newBasic.getId(), currentUser);
                if (!result.isSuccess()){
                    return HttpResult.error(result.getMessage());
                }
            }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPZC)){
                // 药品注册
                Result result = ypzcFlowService.initJob(newBasic.getId(), currentUser);
                if (!result.isSuccess()){
                    return HttpResult.error(result.getMessage());
                }
            }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPJY)){
                // 药品流通
                Result result = ypltFlowService.initJob(newBasic.getId(), currentUser);
                if (!result.isSuccess()){
                    return HttpResult.error(result.getMessage());
                }
            }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YLQX)){
                // 医疗器械
                Result result = ylqxFlowService.initJob(newBasic.getId(), currentUser);
                if (!result.isSuccess()){
                    return HttpResult.error(result.getMessage());
                }
            }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_HZP)){
                // 化妆品
                Result result = hzpFlowService.initJob(newBasic.getId(), currentUser);
                if (!result.isSuccess()){
                    return HttpResult.error(result.getMessage());
                }
            }else {
                log.error("不存在该业务分类: {}",fywflcode);
            }
        }

        return HttpResult.ok("复制成功");
    }

    /**
     * 保存申请事项-审查模式
     */
    @Log(title = "保存申请事项-审查模式")
    @ApiOperation(value = "保存申请事项-审查模式")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true),
            @ApiImplicitParam(name = "fscms",value = "审查模式",required = true)
    })
    @GetMapping(value = "saveSqsxFscms")
    public HttpResult<?> saveSqsxFscms(@RequestParam("sqsxid")String sqsxid,@RequestParam("fscms")String fscms){
        Result result = busService.saveSqsxScms(sqsxid, fscms);
        if (!result.isSuccess()){
            log.error("保存申请事项-审查模式-出错: {}",result.getMessage());
        }

        return HttpResult.ok("选中【"+fscms+"】");
    }

    /**
     * 保存申请事项-审评类型
     */
    @Log(title = "保存申请事项-审评类型")
    @ApiOperation(value = "保存申请事项-审评类型")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true),
            @ApiImplicitParam(name = "fsplx",value = "审评类型",required = true)
    })
    @GetMapping(value = "saveSqsxJsspType")
    public HttpResult<?> saveSqsxJsspType(@RequestParam("sqsxid")String sqsxid,@RequestParam("fsplx")String fsplx){
        Result result = busService.saveSqsxJsspType(sqsxid, fsplx);
        if (!result.isSuccess()){
            log.error("保存申请事项-审评类型-出错: {}",result.getMessage());
            return HttpResult.error("保存申请事项-审评类型-出错: {}"+result.getMessage());
        }

        return HttpResult.ok("选中【"+fsplx+"】");
    }

    /**
     * 通过日期-获取行政审批接口数据
     */
    @Log(title = "通过日期-获取行政审批接口数据")
    @ApiOperation(value = "通过日期-获取行政审批接口数据")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(value = "time",name = "时间",required = true),
            @ApiImplicitParam(value = "fywflcode",name = "业务分类编码",required = true)
    })
    @GetMapping(value = "getXzspData")
    public HttpResult<?> getXzspData(@RequestParam(value = "time",defaultValue = "0")String time,
                                     @RequestParam(value = "fywflcode",defaultValue = "")String ywflcode,
                                     @RequestParam(value = "fsqdbh",defaultValue = "")String sqdbh){
        if (StringUtils.isBlank(time)){
            return HttpResult.error("请选中时间");
        }
        if (StringUtils.isBlank(ywflcode)){
            return HttpResult.error("业务分类编码不能为空");
        }

        // 药品注册-临床
        if (ywflcode.equals(SpcyConstant.YWFL_CODE_YPZCLC)){
            ywflcode = SpcyConstant.YWFL_CODE_YPZC;
        }

        CurrentUserVo currentUser = GetCurrentUserUtils.getCurrentUser();
        xzspJkApi.tqSqsx(time,ywflcode,currentUser,null, sqdbh); // 获取数据

        return HttpResult.ok("获取成功");
    }

    @Log(title = "计算截止日期")
    @ApiOperation(value = "计算截止日期")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "fslsj",value = "开始时间",required = true),
            @ApiImplicitParam(name = "fwcsx",value = "天数",required = true),
    })
    @GetMapping(value = "computeJzrq")
    public HttpResult<?> computeJzrq(@RequestParam("fslsj")String fslsj,
                                     @RequestParam("fwcsx")String fwcsx){
        if (StringUtils.isBlank(fslsj)){
            return HttpResult.error("开始时间不能为空");
        }
        if (StringUtils.isBlank(fwcsx)){
            return HttpResult.error("天数不能为空");
        }
        Map map = new HashMap();
        DateTime slsj = DateUtil.parse(fslsj);
        Date jzsj = spcyRsJjrkService.getJzsj(slsj, Integer.valueOf(fwcsx.trim()));

        map.put("fjzrq",jzsj);
        return HttpResult.ok(map);
    }

    /** -------------------------------------------【 查询相关 - 功能 】--------------------------------------------------------- */

    /** 废弃 */
    @GetMapping(value = "queryHcyPageListOld")
    public HttpResult<?> queryHcyPageListOld(RsHcyVo rsHcyVo,
                                             @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){
        Page<HcyJbxxVo> page = new Page<>(pageNo,pageSize);
        rsHcyVo.setFstate(SpcyCommonConstant.JCY_STATE_YX); // 有效
        rsHcyVo.setFgzzt(SpcyConstant.JCY_ZT_ZG); // 在岗
        if (StringUtils.isNotBlank(rsHcyVo.getHbqy())){
            rsHcyVo.setFssqy(null);
        }

        // 药品注册-临床
        if (StringUtils.isNotBlank(rsHcyVo.getFywflcode()) && rsHcyVo.getFywflcode().equals(SpcyConstant.YWFL_CODE_YPZCLC)){
            rsHcyVo.setFywflcode(SpcyConstant.YWFL_CODE_YPZC);
        }

        /** 药品注册-检查员-在岗+检查日期范围 查询 */
        if (StringUtils.isNotBlank(rsHcyVo.getFywflcode())
                && rsHcyVo.getFywflcode().equals(SpcyConstant.YWFL_CODE_YPZC)
                && rsHcyVo.getKssj() != null
                && StringUtils.isNotBlank(rsHcyVo.getFusertype())
                && rsHcyVo.getFusertype().equals(SpcyConstant.HCY_USERTYPE_JCY)){
            rsHcyVo.setFgzzt(null);
            rsHcyVo.setFwcx("是");
        }

        /** 药品注册-检查员-在岗+检查日期范围 查询 */
        if (StringUtils.isNotBlank(rsHcyVo.getFywflcode())
                && rsHcyVo.getFywflcode().equals(SpcyConstant.YWFL_CODE_YPZC)
                && rsHcyVo.getKssj() != null
                && StringUtils.isNotBlank(rsHcyVo.getFusertype())
                && rsHcyVo.getFusertype().equals(SpcyConstant.HCY_USERTYPE_JCY)){
            rsHcyVo.setFgzzt(null);
            rsHcyVo.setFwcx("是");
        }

        // 请假范围查询
        /*if (rsHcyVo.getKssj() != null && rsHcyVo.getJssj() != null){
            rsHcyVo.setQjfwcx("是");
        }*/

        // 查询检查员类别
        if (StringUtils.isBlank(rsHcyVo.getFlx()) && StringUtils.isNotBlank(rsHcyVo.getFywflcode())) {
            rsHcyVo.setFjcyxl(JcydjbConstant.getJcyXlByYwflcode(rsHcyVo.getFywflcode()));

        }else if (StringUtils.isBlank(rsHcyVo.getFywflcode())){

            rsHcyVo.setFjcyxl(JcydjbConstant.getJcyXlByYwflcode(rsHcyVo.getFywflcode()));
        }
        rsHcyVo.setFywflcode(null);
        rsHcyVo.setFlx(null);

        IPage<HcyJbxxVo> rsHcyList = spcyRsHcyMapper.pageRsHcyJbxxList(page,rsHcyVo);

        return HttpResult.ok(rsHcyList);
    }

    /** 2024-03-13 */
    @Log(title = "查询指定检查员列表-根据申请事项id")
    @ApiOperation(value = "查询指定检查员列表-根据申请事项id")
    @GetMapping(value = "queryHcyPageList")
    public HttpResult queryHcyPageList(RsHcyVo query, PageVo pageVo){

        Page<HcyJbxxVo> page = new Page<>(pageVo.getPageNo(),pageVo.getPageSize());
        query.setFstate(SpcyCommonConstant.JCY_STATE_YX); // 有效

        if (StringUtils.isNotBlank(query.getHbqy())){
            query.setFssqy(null);
        }

        if (StringUtils.isNotBlank(query.getSqsxid())){
            SpcySqsxBasic sqsx = spcySqsxBaiscService.selectSqsxById(query.getSqsxid());
            query.setFywflcode(sqsx.getFywflcode());

            if (sqsx.getFcykssj() != null && sqsx.getFcyjssj() != null) {
                query.setKssj(sqsx.getFcykssj());
                query.setJssj(sqsx.getFcyjssj());
            }
        }else {
            if (StringUtils.isBlank(query.getFywflcode())){
                return HttpResult.error("事项参数为空！");
            }
        }

        /*if (StringUtils.isBlank(query.getFywflcode())){
            if (StringUtils.isBlank(query.getSqsxid())){
                throw new BusinessException("申请事项参数为空！");
            }
            SpcySqsxBasic sqsx = spcySqsxBaiscService.selectSqsxById(query.getSqsxid());
            query.setFywflcode(sqsx.getFywflcode());
            query.setKssj(sqsx.getFcykssj());
            query.setJssj(sqsx.getFcyjssj());
        }*/

        query.setFjcyxl(JcydjbConstant.getJcyXlByYwflcode(query.getFywflcode()));
        query.setFywflcode(null);
        query.setFlx(null);
        query.setFusertype(null);

        // 2024-07-09
        if (StringUtils.isNotBlank(query.getFgpk()) && query.getFgpk().equals(SpcyConstant.JCY_GKP_YES)){
            query.setFgpk(SpcyConstant.JCY_GKP_YES);
        }else {
            query.setFgpk(null);
        }

        if (query.getKssj() == null || query.getJssj() == null){
            IPage<HcyJbxxVo> pageList = spcyRsHcyMapper.pageRsHcyJbxxList(page,query);

            return HttpResult.ok(pageList);
        }else {

            /** 在这个检查范围有任务的人员,标识是否执行任务 */
            query.setCxkssj(DateConversionUtils.DateToStringYYYYMMDD(query.getKssj()));
            query.setCxjssj(DateConversionUtils.DateToStringYYYYMMDD(query.getJssj()));
            IPage<HcyJbxxVo> pageList = spcyRsHcyMapper.pageJcyXpList(page, query);
            for (HcyJbxxVo bean : pageList.getRecords()) {
                if (bean.getBxpsl() > 0) {
                    bean.setFgzzt(SpcyConstant.JCY_ZY_ZXRWZ);
                }else {
                    bean.setFgzzt(SpcyConstant.JCY_ZT_ZG);
                }
            }
            return HttpResult.ok(pageList);
        }
    }

    /** 2024-03-13 */
    @Log(title = "获取申请事项所有检查员选派记录分页列表")
    @ApiOperation(value = "获取申请事项所有检查员选派记录分页列表")
    @GetMapping(value = "queryJcyAllXpPageList")
    public HttpResult queryJcyAllXpPageList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid,
                                            @RequestParam(value = "key",defaultValue = "")String key,
                                            PageVo pageVo){

        IPage<SpcySqsxXpjl> pageList = spcySqsxXpjlService.getXpjlPageListBySqsxId(sqsxid, key, pageVo.getPageNo(), pageVo.getPageSize());

        return HttpResult.ok(pageList);
    }

    /** 2024-03-13 */
    @Log(title = "获取申请事项所有检查员同意选派记录列表")
    @ApiOperation(value = "获取申请事项所有检查员同意选派记录列表")
    @GetMapping(value = "queryJcyTyXpList")
    public HttpResult queryJcyTyXpList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        Map map = new HashMap();

        // 所有同意列表
        List<SpcySqsxXpjl> tyXpjlList = spcySqsxXpjlService.getTyXpXpjlList(sqsxid, null);

        // 所有不同意列表
        List<SpcySqsxXpjl> dqrXpXpjlList = spcySqsxXpjlService.getDqrXpXpjlList(sqsxid, null, true);

        /*List<SpcySqsxXpjl> zzXpjlList = tyXpjlList.stream().filter(d -> StringUtils.isBlank(d.getFssk()) || d.getFssk().contains(SpcyConstant.HCY_SSK_ZZ)).collect(Collectors.toList());
        List<SpcySqsxXpjl> zyXpjlList = tyXpjlList.stream().filter(d -> StringUtils.isBlank(d.getFssk()) || d.getFssk().contains(SpcyConstant.HCY_SSK_ZY)).collect(Collectors.toList());
        List<SpcySqsxXpjl> ybXpjlList = tyXpjlList.stream().filter(d -> StringUtils.isBlank(d.getFssk()) || d.getFssk().contains(SpcyConstant.HCY_SSK_YB)).collect(Collectors.toList());

        map.put("zzXpjlList", zzXpjlList);
        map.put("zyXpjlList", zyXpjlList);
        map.put("ybXpjlList", ybXpjlList);*/

        map.put("tyXpjlList", tyXpjlList); // 所有同意选派记录

        map.put("btyXpjlList", dqrXpXpjlList); // 待确认选派记录

        return HttpResult.ok(map);
    }

    @Log(title = "获取申请事项-核查员选派记录")
//    @ApiOperation(value = "获取申请事项-核查员选派记录")
    @GetMapping(value = "queryHcyXpList")
    public HttpResult<?> queryHcyXpList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项id不能为空");
        }
        Map map = new HashMap();
        List<SpcySqsxXpjl> xpjl = busService.getXpjlBySqsxId(sqsxid, SpcyConstant.FLOW_TYPE_CY);
        List<SpcySqsxXpjl> zzXpjlList = xpjl.stream().filter(d -> StringUtils.isBlank(d.getFssk()) || d.getFssk().contains(SpcyConstant.HCY_SSK_ZZ)).collect(Collectors.toList());
        List<SpcySqsxXpjl> zyXpjlList = xpjl.stream().filter(d -> StringUtils.isBlank(d.getFssk()) || d.getFssk().contains(SpcyConstant.HCY_SSK_ZY)).collect(Collectors.toList());
        List<SpcySqsxXpjl> ybXpjlList = xpjl.stream().filter(d -> StringUtils.isBlank(d.getFssk()) || d.getFssk().contains(SpcyConstant.HCY_SSK_YB)).collect(Collectors.toList());

        map.put("zzXpjlList",zzXpjlList);
        map.put("zyXpjlList",zyXpjlList);
        map.put("ybXpjlList",ybXpjlList);

        Map initWjjlList = spcyBlgcclService.selectFazdWjList(sqsxid);
        map.putAll(initWjjlList);
        return HttpResult.ok(map);
    }

    @Log(title = "获取申请事项-审评专家选派记录")
//    @ApiOperation(value = "获取申请事项-审评专家选派记录")
    @GetMapping(value = "querySpHcyXpList")
    public HttpResult<?> querySpHcyXpList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项id不能为空");
        }
        Map map = new HashMap();
        List<SpcySqsxXpjl> xpjl = busService.getXpjlBySqsxId(sqsxid, SpcyConstant.FLOW_TYPE_SP);

        List<SpcySqsxXpjl> zzXpjlList = new ArrayList<>();
        List<SpcySqsxXpjl> zyXpjlList = new ArrayList<>();
        CurrentUserVo currentUser = GetCurrentUserUtils.getCurrentUser();

        if (currentUser != null && (currentUser.getDeptName().equals(SpcyConstant.HCY_ZJ_ORGNAME) || currentUser.getDeptName().equals(SpcyConstant.HCY_ORGNAME))){
            zzXpjlList = xpjl.stream()
                    .filter(d -> d.getFuserid().equals(currentUser.getId()))
                    .collect(Collectors.toList());

            zyXpjlList = xpjl.stream()
                    .filter(d -> d.getFuserid().equals(currentUser.getId()))
                    .collect(Collectors.toList());

        }else {

            zzXpjlList = xpjl.stream()
                    .filter(d -> StringUtils.isBlank(d.getFssk()) || d.getFssk().contains(SpcyConstant.HCY_SSK_ZZ))
                    .collect(Collectors.toList());

            zyXpjlList = xpjl.stream()
                    .filter(d -> StringUtils.isBlank(d.getFssk()) || d.getFssk().contains(SpcyConstant.HCY_SSK_ZY))
                    .collect(Collectors.toList());
        }

        map.put("spzzXpjlList",zzXpjlList);
        map.put("spzyXpjlList",zyXpjlList);
        map.put("spZjList",xpjl);

        Map initWjjlList = busService.getInitSpFazzWjjlList(sqsxid);
        map.putAll(initWjjlList);
        return HttpResult.ok(map);
    }

    @Log(title = "获取申请事项-整改人员选派记录")
//    @ApiOperation(value = "获取申请事项-整改人员选派记录")
    @GetMapping(value = "queryZgHcyXpList")
    public HttpResult<?> queryZgHcyXpList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项id不能为空");
        }

        Map map = new HashMap();
        List<SpcySqsxXpjl> xpjl = busService.getXpjlBySqsxId(sqsxid, SpcyConstant.FLOW_TYPE_ZG);
        List<SpcySqsxXpjl> zzXpjlList = xpjl.stream()
                .filter(d -> StringUtils.isBlank(d.getFssk()) || d.getFssk().contains(SpcyConstant.HCY_SSK_ZZ))
                .collect(Collectors.toList());

        List<SpcySqsxXpjl> zyXpjlList = xpjl.stream()
                .filter(d -> StringUtils.isBlank(d.getFssk()) || d.getFssk().contains(SpcyConstant.HCY_SSK_ZY))
                .collect(Collectors.toList());

        map.put("zgzzXpjlList",zzXpjlList);
        map.put("zgzyXpjlList",zyXpjlList);

        return HttpResult.ok(map);
    }

    @Log(title = "查询核查员-通过选派id")
//    @ApiOperation(value = "查询核查员-通过选派id")
    @GetMapping(value = "queryHcyByXpId")
    public HttpResult<?> queryHcyByXpId(@RequestParam(value = "fbusid",defaultValue = "")String fbusid){
        if (StringUtils.isBlank(fbusid)){
            return HttpResult.error("参数为空！请联系管理员！");
        }
        SpcySqsxXpjl xpjl = spcySqsxXpjlService.getById(fbusid);
        if (xpjl == null){
            return HttpResult.error("当前选派记录不存在，请重试");
        }
        SpcyRsHcy hcy = spcyRsHcyService.getById(xpjl.getFjcyid());
        YcSysUser user = null;
        if (hcy != null){
            user = ycSysUserService.getById(hcy.getFuserid());
        }
        return HttpResult.ok(user);
    }

    @Log(title = "获取现场检查环节-初始化文件记录")
//    @ApiOperation(value = "获取现场检查环节-初始化文件记录")
    @GetMapping(value = "queryXcjcWjjl")
    public HttpResult<?> queryXcjcWjjl(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数不能为空！请联系管理员！");
        }

        Map initXcjcWjjlList = busService.getInitXcjcWjjlList(sqsxid);
        return HttpResult.ok(initXcjcWjjlList);
    }

    @Log(title = "获取技术审评环节-初始化文件记录")
//    @ApiOperation(value = "获取技术审评环节-初始化文件记录")
    @GetMapping(value = "queryXcspWjjl")
    public HttpResult<?> queryXcspWjjl(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空！请联系管理员！");
        }
        Map initXcjcWjjlList = busService.getInitJsspWjjlList(sqsxid);
        return HttpResult.ok(initXcjcWjjlList);
    }

    @Log(title = "获取其他环节-初始化文件记录")
//    @ApiOperation(value = "获取其他环节-初始化文件记录")
    @GetMapping(value = "queryInitQtWjjlList")
    public HttpResult<?> queryInitQtWjjlList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空！请联系管理员！");
        }
        Map initXcjcWjjlList = busService.getInitQtWjjlList(sqsxid);
        return HttpResult.ok(initXcjcWjjlList);
    }

    @Log(title = "获取审评中心-补齐补正材料")
//    @ApiOperation(value = "获取审评中心-补齐补正材料")
    @GetMapping(value = "queryBqbzWjjlList")
    public HttpResult queryBqbzWjjlList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空！请联系管理员！");
        }

        List<SpcySqsxWjjl> wjjlList = busService.queryBqbzWjjlList(sqsxid);

        Map result = new HashMap();
        result.put("zxbqbzList",wjjlList);
        return HttpResult.ok(result);
    }

    @Log(title = "获取审评中心-整改材料")
//    @ApiOperation(value = "获取审评中心-整改材料")
    @GetMapping(value = "queryZgWjjlList")
    public HttpResult queryZgWjjlList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空！请联系管理员！");
        }

        List<SpcySqsxWjjl> wjjlList = busService.queryZgWjjlList(sqsxid);

        Map result = new HashMap();
        result.put("zxzgList",wjjlList);
        return HttpResult.ok(result);
    }

    @Log(title = "获取审评中心-中心制作材料")
//    @ApiOperation(value = "获取审评中心-中心制作材料")
    @GetMapping(value = "queryZxzzWjjlList")
    public HttpResult queryZxzzWjjlList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空！请联系管理员！");
        }

        List<SpcySqsxWjjl> wjjlList = busService.queryZgWjjlList(sqsxid);

        Map result = new HashMap();
        result.put("zxzzclList",wjjlList);
        return HttpResult.ok(result);
    }

    @Log(title = "获取申请事项-六大类文件记录（检查的情况专述、质量管理、机构与人员、厂房与设施、设备、物料与产品等）")
    /*@ApiOperation(value = "获取申请事项-六大类文件记录（检查的情况专述、质量管理、机构与人员、厂房与设施、设备、物料与产品等）")
    @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true)*/
    @GetMapping(value = "querySixTypeFileList")
    public HttpResult<?> querySixTypeFileList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空！请联系管理员！");
        }

        Map map = busService.querySixTypeFileList(sqsxid);
        return HttpResult.ok(map);
    }

    @Log(title = "获取申请事项-补齐补正历史")
    @ApiOperation(value = "获取申请事项-补齐补正历史")
    @GetMapping(value = "querySqsxBqbzjlHistoryList")
    public HttpResult querySqsxBqbzjlHistoryList(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空！请联系管理员！");
        }
        List<SpcySqsxBqbzjl> list = busService.getSqsxBqbzjlHistoryList(sqsxid);

        Map resultMap = new HashMap();
        resultMap.put("records",list);
        return HttpResult.ok(resultMap);
    }

    @Log(title = "获取申请事项-补充整改历史")
    @ApiOperation(value = "获取申请事项-补充整改历史")
    @GetMapping(value = "querySqsxBczgjlHistoryList")
    public HttpResult querySqsxBczgjlHistoryList(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空！请联系管理员！");
        }
        List<SpcySqsxBczgjl> list = busService.getSqsxBczgjlHistoryList(sqsxid);

        Map resultMap = new HashMap();
        resultMap.put("records",list);
        return HttpResult.ok(resultMap);
    }

    @Log(title = "查询申请事项-详情信息-通过申请事项id")
    @ApiOperation(value = "查询申请事项-详情信息-通过申请事项id")
    @GetMapping(value = "querySqsxDetailsById")
    public HttpResult<?> querySqsxDetailsById(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空！请联系管理员！");
        }
        Map map = busService.querySqsxDetailsById(sqsxid);

        return HttpResult.ok(map);
    }

    /** --------------------------------------【 保存选派 - 功能 】--------------------------------------------------------- */

    @Log(title = "保存-手动选派检查员")
    @ApiOperation(value = "保存-手动选派检查员")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true),
            @ApiImplicitParam(name = "hcyids",value = "检查员ids",required = true),
            @ApiImplicitParam(name = "fbz",value = "选派原因",required = true),
            @ApiImplicitParam(name = "kssj",value = "开始时间",required = true),
            @ApiImplicitParam(name = "jssj",value = "结束时间",required = true)
    })
    @PostMapping(value = "xpHcyByHand")
    public HttpResult<?> xpHcyByHand(@RequestBody RsHcyVo paramBo){
        String sqsxid = paramBo.getSqsxid();
        String hcyids = paramBo.getHcyids();
        Date kssj = paramBo.getKssj();
        Date jssj = paramBo.getJssj();

        Result result = busService.xpHcyByHand(paramBo, sqsxid, hcyids, SpcyConstant.HCY_USERTYPE_JCY, kssj, jssj);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }
        return HttpResult.ok("选派成功");
    }

    @Log(title = "自动随机检查员")
    /*@ApiOperation(value = "自动随机检查员")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true),
            @ApiImplicitParam(name = "fusertype",value = "人员分类（检查员、专家）",required = true),
            @ApiImplicitParam(name = "fywflcode",value = "业务分类编码",required = true),
            @ApiImplicitParam(name = "fssk",value = "所属库",required = true)
    })*/
    @GetMapping(value = "xpHcyByAuto")
    public HttpResult<?> xpHcyByAuto(HcyXpVo hcyXpVo){
        String sqsxid = hcyXpVo.getSqsxid();
        String fywflcode = hcyXpVo.getFywflcode();
        String fssqy = hcyXpVo.getFssqy();
        String fusertype = hcyXpVo.getFusertype();
        String zytc = hcyXpVo.getZytc();
        String hbqy = hcyXpVo.getHbqy();
        String kssj = hcyXpVo.getKssj();
        String jssj = hcyXpVo.getJssj();
        String ssk = hcyXpVo.getFssk();
        Integer fzyrs = hcyXpVo.getFzyrs();
        Integer fzzrs = hcyXpVo.getFzzrs();
        Integer fybrs = hcyXpVo.getFybrs();
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项id不能为空");
        }

        if (StringUtils.isBlank(fusertype)){
            fusertype = SpcyConstant.HCY_USERTYPE_JCY;
        }

        SpcySqsxBasic sqsx = spcySqsxBaiscService.selectSqsxInfoById(sqsxid);
        if (sqsx == null){
            throw new BusinessException("当前申请事项数据不存在，请联系管理员！");
        }
        if (StringUtils.isBlank(fywflcode)){
            fywflcode = sqsx.getFywflcode();
        }

        // 药品生产-随机选人
        if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPSC)){
            Result<?> result = busService.xpHcyByAutoInYpsc(hcyXpVo,sqsxid, sqsx, ssk, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs,"", SpcyConstant.XPFS_ZDXZ);
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPJY)){
            Result<?> result = busService.xpHcyByAutoInYplt(hcyXpVo,sqsxid, sqsx, ssk, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPZC)){
            Result<?> result = busService.xpHcyByAutoInYpzc(hcyXpVo,sqsxid, sqsx, ssk, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_HZP)){
            Result<?> result = busService.xpHcyByAutoInHzp(hcyXpVo,sqsxid, sqsx, ssk, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPZCLC)){
            Result<?> result = busService.xpHcyByAutoInYpzcLc(hcyXpVo,sqsxid, sqsx, ssk, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YLQX)){
            Result<?> result = busService.xpHcyByAutoInYlqx(hcyXpVo,sqsxid, sqsx, ssk, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else {
            Result<?> result = busService.xpHcyByAuto(hcyXpVo,sqsxid, sqsx, ssk, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }

        return HttpResult.ok("选派成功");
    }

    @Log(title = "一键自动随机检查员")
    /*@ApiOperation(value = "一键自动随机检查员")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true),
            @ApiImplicitParam(name = "fusertype",value = "人员分类（检查员、专家）",required = true),
            @ApiImplicitParam(name = "fywflcode",value = "业务分类编码",required = true),
            @ApiImplicitParam(name = "fssk",value = "所属库",required = true)
    })*/
    @GetMapping(value = "oneTouchHcyByAuto")
    public HttpResult oneTouchHcyByAuto(HcyXpVo hcyXpVo){
        if (StringUtils.isBlank(hcyXpVo.getSqsxid())){
            return HttpResult.error("申请事项参数不能为空！");
        }

        if (StringUtils.isBlank(hcyXpVo.getFusertype())){
            hcyXpVo.setFusertype(SpcyConstant.HCY_USERTYPE_JCY);
        }

        String sqsxid = hcyXpVo.getSqsxid();
        String fywflcode = hcyXpVo.getFywflcode();
        String fssqy = hcyXpVo.getFssqy();
        String fusertype = hcyXpVo.getFusertype();
        String zytc = hcyXpVo.getZytc();
        String hbqy = hcyXpVo.getHbqy();
        String kssj = hcyXpVo.getKssj();
        String jssj = hcyXpVo.getJssj();
        String ssk = hcyXpVo.getFssk();

        Integer fzzrs = hcyXpVo.getFzzrs();
        Integer fzyrs = hcyXpVo.getFzyrs();
        Integer fybrs = hcyXpVo.getFybrs();

        SpcySqsxBasic sqsx = spcySqsxBaiscService.selectSqsxInfoById(sqsxid);
        if (sqsx == null){
            return HttpResult.error("没想匹配的事项数据！");
        }
        if (sqsx.getFcykssj() == null || sqsx.getFcyjssj() == null){
            return HttpResult.error("请选择检查时间！");
        }

        if (StringUtils.isBlank(fywflcode)){
            fywflcode = sqsx.getFywflcode();
        }

        // 药品生产-随机选人
        if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPSC)){
            /** 初始化选派条件记录 */
            String fxptjid = GetUuIdUtils.ReplaceUuId();
            String xpfs = SpcyConstant.XPFS_ZDXZ;
            spcySqsxXptjjlService.initXptjjl(fxptjid, hcyXpVo.getSqsxid(), xpfs, hcyXpVo, 0, 0, 0, "");

            StringBuffer errorMsg = new StringBuffer();

            if (fzzrs > 0){
                Result result = busService.xpHcyByAutoInYpsc(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_ZZ, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs,fxptjid, xpfs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (fzyrs > 0){
                Result result = busService.xpHcyByAutoInYpsc(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_ZY, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs,fxptjid, xpfs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (fybrs > 0){
                Result result = busService.xpHcyByAutoInYpsc(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_YBK, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs,fxptjid, xpfs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (!StringPatternUtils.verifryIsEmptyStringBuffer(errorMsg)){
                return HttpResult.error(errorMsg.toString());
            }

        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPJY)){
            StringBuffer errorMsg = new StringBuffer();

            if (fzzrs > 0){
                Result result = busService.xpHcyByAutoInYplt(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_ZZ, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (fzyrs > 0){
                Result result = busService.xpHcyByAutoInYplt(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_ZY, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (fybrs > 0){
                Result result = busService.xpHcyByAutoInYplt(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_YBK, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (!StringPatternUtils.verifryIsEmptyStringBuffer(errorMsg)){
                return HttpResult.error(errorMsg.toString());
            }

        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPZC)){
            StringBuffer errorMsg = new StringBuffer();

            if (fzzrs > 0){
                Result result = busService.xpHcyByAutoInYpzc(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_ZZ, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (fzyrs > 0){
                Result result = busService.xpHcyByAutoInYpzc(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_ZY, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (fybrs > 0){
                Result result = busService.xpHcyByAutoInYpzc(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_YBK, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (!StringPatternUtils.verifryIsEmptyStringBuffer(errorMsg)){
                return HttpResult.error(errorMsg.toString());
            }

        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_HZP)){

            StringBuffer errorMsg = new StringBuffer();

            if (fzzrs > 0){
                Result result = busService.xpHcyByAutoInHzp(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_ZZ, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (fzyrs > 0){
                Result result = busService.xpHcyByAutoInHzp(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_ZY, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (fybrs > 0){
                Result result = busService.xpHcyByAutoInHzp(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_YBK, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (!StringPatternUtils.verifryIsEmptyStringBuffer(errorMsg)){
                return HttpResult.error(errorMsg.toString());
            }

        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YLQX)){
            StringBuffer errorMsg = new StringBuffer();

            if (fzzrs > 0){
                Result result = busService.xpHcyByAutoInYlqx(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_ZZ, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (fzyrs > 0){
                Result result = busService.xpHcyByAutoInYlqx(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_ZY, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (fybrs > 0){
                Result result = busService.xpHcyByAutoInYlqx(hcyXpVo,sqsxid, sqsx, SpcyConstant.HCY_SSK_YBK, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
                if (!result.isSuccess()) {
                    errorMsg.append(result.getMessage());
                }
            }

            if (!StringPatternUtils.verifryIsEmptyStringBuffer(errorMsg)){
                return HttpResult.error(errorMsg.toString());
            }

        }else {
            Result<?> result = busService.xpHcyByAuto(hcyXpVo,sqsxid, sqsx, ssk, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs);
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }

        return HttpResult.ok("选派成功");
    }

    @Log(title = "自动选派专家")
    /*@ApiOperation(value = "自动选派专家")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true),
            @ApiImplicitParam(name = "fusertype",value = "人员分类（检查员、专家）",required = true),
            @ApiImplicitParam(name = "fywflcode",value = "业务分类编码",required = true),
            @ApiImplicitParam(name = "fssk",value = "所属库",required = true)
    })*/
    @GetMapping(value = "xpZjByAutoInCommon")
    public HttpResult<?> xpZjByAutoInCommon(HcyXpVo hcyXpVo){
        String sqsxid = hcyXpVo.getSqsxid();
        String fywflcode = hcyXpVo.getFywflcode();
        String fssqy = hcyXpVo.getFssqy();
        String fusertype = hcyXpVo.getFusertype();
        String zytc = hcyXpVo.getZytc();
        String hbqy = hcyXpVo.getHbqy();
        String kssj = hcyXpVo.getKssj();
        String jssj = hcyXpVo.getJssj();
        String ssk = hcyXpVo.getFssk();
        Integer fzyrs = hcyXpVo.getFzyrs();
        Integer fzzrs = hcyXpVo.getFzzrs();
        Integer fybrs = hcyXpVo.getFybrs();
        Integer fzjrs = hcyXpVo.getFzjrs();

        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项id不能为空");
        }

        /*if (StringUtils.isBlank(fusertype)){
            fusertype = SpcyConstant.HCY_USERTYPE_ZJ; // 专家
        }*/
        /*if (StringUtils.isBlank(fywflcode)){
            return HttpResult.error("业务分类编码不能为空");
        }*/
        /*if (StringUtils.isBlank(ssk)){
            return HttpResult.error("所属库不能为空");
        }*/
        fusertype = SpcyConstant.HCY_USERTYPE_ZJ; // 专家

        SpcySqsxBasic sqsx = spcySqsxBaiscService.selectSqsxInfoById(sqsxid);
        if (sqsx == null){
            throw new BusinessException("当前申请事项数据不存在，请联系管理员！");
        }

        if (StringUtils.isBlank(fywflcode)){
            fywflcode = sqsx.getFywflcode();
        }

        Result<?> result = busService.xpZjByAutoInCommon(sqsxid, sqsx, ssk, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs,fybrs,fzjrs);
        if (!result.isSuccess()) {
            return HttpResult.error(result.getMessage());
        }


        return HttpResult.ok("选派成功");
    }

    @Log(title = "删除选派的核查员")
    @ApiOperation(value = "删除选派的核查员")
    @GetMapping(value = "deleteXpHcy")
    public HttpResult<?> deleteXpHcy(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid,
                                    @RequestParam(value = "xpjlid",defaultValue = "")String xpids){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空！请联系管理员！");
        }
        if (StringUtils.isBlank(xpids)){
            return HttpResult.error("选派记录参数为空！请联系管理员！");
        }
        String dhRegex = ",|，"; // 不区分 中英文逗号，正则表达式
        List<String> idsList = Arrays.asList(xpids.split(dhRegex));
        if (CollectionUtils.isNotEmpty(idsList)) {
            for (String xpid : idsList) {
                Result result = busService.deleteXpHcy(sqsxid, xpid);
                if (!result.isSuccess()) {
                    return HttpResult.error(result.getMessage());
                }

                List<SpcySqsxWjjl> wjjlList = spcySqsxWjjlService.list(new LambdaQueryWrapper<SpcySqsxWjjl>()
                        .eq(SpcySqsxWjjl::getFpid, sqsxid)
                        .eq(SpcySqsxWjjl::getFbusid, xpid));
                if (CollectionUtils.isNotEmpty(wjjlList)) {
                    for (SpcySqsxWjjl wjjl : wjjlList) {
                        spcySqsxWjjlService.removeById(wjjl.getId());
                        localFileUploadUtils.deleteLocalFileUrl(wjjl.getFcflj());

                        if (StringUtils.isNotBlank(wjjl.getFjdcflj())){
                            localFileUploadUtils.deleteLocalFileUrl(wjjl.getFjdcflj());
                        }
                    }
                }
            }
        }

        return HttpResult.ok("删除成功");
    }

    @Log(title = "申请事项-修改选派人员信息(修改同意/不同意)")
    @ApiOperation(value = "申请事项-修改选派人员信息(修改同意/不同意)")
    @PutMapping(value = "updateXpHcyxx")
    public HttpResult<?> updateXpHcyxx(@RequestBody SpcySqsxXpjl xpjl){

        xpryTimedTasksService.updateXpJcyxxInSfty(xpjl);

        return HttpResult.ok("修改成功");
    }

    @Log(title = "申请事项-选择观察员")
    @ApiOperation(value = "申请事项-选择观察员")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true),
            @ApiImplicitParam(name = "id",value = "观察员id",required = true),
    })
    @GetMapping(value = "selectSqsxGcy")
    public HttpResult<?> selectSqsxGcy(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxId,
                                       @RequestParam(value = "id",defaultValue = "")String id){
        if (StringUtils.isBlank(sqsxId)){
            return HttpResult.error("申请事项参数为空！请联系管理员！");
        }
        if (StringUtils.isBlank(id)){
            return HttpResult.error("观察员参数为空！请联系管理员！");
        }

        SpcySqsxBasic sqsx = spcySqsxBaiscService.selectSqsxById(sqsxId);
        if (sqsx == null){
            return HttpResult.error("当前申请事项为空！请刷新重试并联系管理员！");
        }

        SpcyRsGcy gcy = spcyRsGcyService.getById(id);
        if (gcy == null){
            return HttpResult.error("观察员不存在，请刷新重试并联系管理员！");
        }

        LambdaUpdateWrapper<SpcySqsxBasic> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SpcySqsxBasic::getId, sqsxId);

        SpcySqsxBasic updateBean = new SpcySqsxBasic();
        updateBean.setFcygcyid(id);
        updateBean.setFcygcybm(gcy.getFdwmc());
        updateBean.setFcygcy(gcy.getFgcyxm());

        spcySqsxBaiscService.update(updateBean, updateWrapper);

        String logNr = "选择观察员: 【观察员id】从["+sqsx.getFcygcyid()+"]设置为["+id+"];" +
                "【观察员姓名】从["+sqsx.getFcygcy()+"]设置为["+gcy.getFgcyxm()+"];" +
                "【观察员部门】从["+sqsx.getFcygcybm()+"]设置为["+gcy.getFdwmc()+"];";


        spcyLogService.addLogs("方案制作",logNr,sqsxId,LogConstant.LOGS_SQSX_BASIC,SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("选择成功");
    }

    @Log(title = "保存核查员-电话基本信息")
    @ApiOperation(value = "保存核查员-电话基本信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id",value = "用户id",required = true),
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true),
            @ApiImplicitParam(name = "phone",value = "电话",required = false),
            @ApiImplicitParam(name = "email",value = "邮箱",required = false)
    })
    @PutMapping(value = "updateHcyJbxx")
    public HttpResult<?> updateHcyJbxx(@RequestBody HashMap<String,String> buffer){
        String id = buffer.get("id");
        String sqsxid = buffer.get("sqsxid");

        YcSysUser userUpdate = ycSysUserService.getById(id);
        if (userUpdate == null){
            return HttpResult.error("用户不存在，请重试!");
        }

        String oldUsername = userUpdate.getUsername();
        String oldPhone = userUpdate.getPhone();
        String oldFsfzh = userUpdate.getFsfzh();

        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(userUpdate);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        try {
            BeanUtils.populate(userUpdate, buffer);
        } catch (IllegalAccessException e) {
            log.error("保存核查员-电话基本信息出错-【IllegalAccessException】- {}",e.getMessage());
        } catch (InvocationTargetException e) {
            log.error("保存核查员-电话基本信息出错-【InvocationTargetException】",e.getMessage());
        }

        ycSysUserService.verifyUserInAccount(oldUsername, userUpdate.getUsername());
        ycSysUserService.verifyUserInPhone(oldPhone, userUpdate.getPhone());
        ycSysUserService.verifyUserInSfzh(oldFsfzh, userUpdate.getFsfzh());

        ycSysUserService.updateById(userUpdate);

        // 当前环节名称
        String operContent = SpcyFlowConstant.HJMC_FAZZ+"/基本信息修改用户信息：";
        operContent += LogUtils.BeanModifyMsg(userUpdate,oldMap);
        spcyLogService.addLogs(LogConstant.LOGS_JCYGL,operContent,id,"保存检查员-电话基本信息",SpcyConstant.LOGS_SYS_TYPE_XG);

        if (StringUtils.isNotBlank(sqsxid)) {
            List<SpcySqsxXpjl> userXpjl = spcySqsxXpjlService.list(new LambdaQueryWrapper<SpcySqsxXpjl>()
                    .eq(SpcySqsxXpjl::getFuserid, id)
                    .eq(SpcySqsxXpjl::getFsqsxid, sqsxid));
            if (CollectionUtils.isNotEmpty(userXpjl)) {
                for (SpcySqsxXpjl xpjl : userXpjl){
                    xpjl.setFjcyyx(userUpdate.getEmail());
                    xpjl.setFjcylxdh(userUpdate.getPhone());
                    spcySqsxXpjlService.updateById(xpjl);
                }
            }
        }
        return HttpResult.ok("保存成功");
    }

    @Log(title = "重新生成现场检查-检查项目库")
//    @ApiOperation(value = "重新生成现场检查-检查项目库")
    @GetMapping(value = "againSqsxJcxmBySqsxid")
    public HttpResult againSqsxJcxmBySqsxid(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        boolean remove = spcySqsxJcxmService.remove(new LambdaQueryWrapper<SpcySqsxJcxm>()
                .eq(SpcySqsxJcxm::getFsqsxid, sqsxid));
        if (remove) {
            spcySqsxJcxmService.fzRsJcxmToSqsxJcxm(sqsxid);

            String log = "重新生成现场检查-检查项目库";
            spcyLogService.addLogs(LogConstant.LOGS_SQSX_JCXM,log,sqsxid,SpcyConstant.LOGS_SYS_TYPE_SC,SpcyConstant.LOGS_SYS_TYPE_SC);
        }else {
            return HttpResult.error("操作失败");
        }

        return HttpResult.ok("操作成功");
    }

    @Log(title = "重新添加流程任务待办人")
    @ApiOperation(value = "重新添加流程任务待办人")
    @PostMapping(value = "againAddFlowJobDbrid")
    public HttpResult againAddFlowJobDbrid(@RequestBody FlowDbrParamBo paramBo){
        if (StringUtils.isBlank(paramBo.getDbrid())){
            return HttpResult.error("请选择待办人！");
        }
        if (StringUtils.isBlank(paramBo.getJobid())){
            return HttpResult.error("流程任务参数为空！");
        }
        Result result = busService.againAddFlowJobDbrId(paramBo.getJobid(), paramBo.getDbrid());
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("操作成功");
    }

    /** -------------------------------------------【 发送短信 - 功能 】--------------------------------------------------------- */

    @Log(title = "对文件的函-发送短信和邮箱")
    @ApiOperation(value = "对文件的函-发送短信和邮箱")
    @GetMapping(value = "sendSmsToFile")
    public HttpResult<?> sendSmsToFile(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid,
                                       @RequestParam(value = "id",defaultValue = "")String fileId){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空！操作失败！");
        }

        if (StringUtils.isBlank(fileId)){
            return HttpResult.error("文件参数为空！操作失败！");
        }

        SpcySqsxWjjl wjjl = spcySqsxWjjlService.getById(fileId);
        String wjlx = "";
        if (wjjl != null){
            wjlx = wjjl.getFwjlx1();
        }
        if (wjlx.equals(WjmlConstant.xpxcscydh)){
            // 选派现场审查员的函
            Result result = busService.sendSmsToHcy(sqsxid, wjjl.getFbusid(), fileId, wjjl);// 短信
            if (!result.isSuccess()){
                return HttpResult.error(result.getMessage());
            }

            Result result1 = busService.sendEmailToHcy(sqsxid, wjjl.getFbusid(), fileId, wjjl, SpcyConstant.HCY_USERTYPE_JCY);// 邮箱
            if (!result1.isSuccess()){
                return HttpResult.error(result.getMessage());
            }
        }else if (wjlx.equals(WjmlConstant.xpxcgcydh)){
            // 选派现场观察员的函
            Result result = busService.sendSmsToGcy(sqsxid, fileId, wjjl);// 短信
            if (!result.isSuccess()){
                return HttpResult.error(result.getMessage());
            }

            Result result1 = busService.sendEmailToGcy(sqsxid, fileId, wjjl);// 邮箱
            if (!result1.isSuccess()){
                return HttpResult.error(result.getMessage());
            }
        }else if (wjlx.equals(WjmlConstant.qydwjctz)){
            // 企业单位检查通知
            Result result = busService.sendSmsToQy(sqsxid, fileId, wjjl);// 短信
            if (!result.isSuccess()){
                return HttpResult.error(result.getMessage());
            }

            Result result1 = busService.sendEmailToQy(sqsxid, fileId, wjjl);// 邮箱
            if (!result1.isSuccess()){
                return HttpResult.error(result.getMessage());
            }
        }else if (wjlx.equals(WjmlConstant.bztz)){
            // 补正通知
            Result result = busService.sendSmsToQy(sqsxid, fileId, wjjl);// 短信
            if (!result.isSuccess()){
                return HttpResult.error(result.getMessage());
            }

            Result result1 = busService.sendEmailToQy(sqsxid, fileId, wjjl);// 邮箱
            if (!result1.isSuccess()){
                return HttpResult.error(result.getMessage());
            }
        }else if (wjlx.equals(WjmlConstant.hstz)){
            // 函审通知
            Result result = busService.sendSmsToHcy(sqsxid, wjjl.getFbusid(), fileId, wjjl);// 短信
            if (!result.isSuccess()){
                return HttpResult.error(result.getMessage());
            }

            Result result1 = busService.sendEmailToHcy(sqsxid, wjjl.getFbusid(), fileId, wjjl, SpcyConstant.HCY_USERTYPE_ZJ);// 邮箱
            if (!result1.isSuccess()){
                return HttpResult.error(result.getMessage());
            }
        }else if (wjlx.equals(WjmlConstant.qytzs)){
            // 企业通知书
            Result result = busService.sendSmsToQy(sqsxid, fileId, wjjl);// 短信
            if (!result.isSuccess()){
                return HttpResult.error(result.getMessage());
            }

            Result result1 = busService.sendEmailToQy(sqsxid, fileId, wjjl);// 邮箱
            if (!result1.isSuccess()){
                return HttpResult.error(result.getMessage());
            }
        }else if (wjlx.equals(WjmlConstant.zgtzs)){
            // 整改通知书
            Result result = busService.sendSmsToQy(sqsxid, fileId, wjjl);// 短信
            if (!result.isSuccess()){
                return HttpResult.error(result.getMessage());
            }

            Result result1 = busService.sendEmailToQy(sqsxid, fileId, wjjl);// 邮箱
            if (!result1.isSuccess()){
                return HttpResult.error(result.getMessage());
            }
        }else if (wjlx.equals(WjmlConstant.jczgclyq)){
            // 检查整改材料要求
            Result result = busService.sendSmsToQy(sqsxid, fileId, wjjl);// 短信
            if (!result.isSuccess()){
                return HttpResult.error(result.getMessage());
            }

            Result result1 = busService.sendEmailToQy(sqsxid, fileId, wjjl);// 邮箱
            if (!result1.isSuccess()){
                return HttpResult.error(result.getMessage());
            }
        }else if (wjlx.equals(WjmlConstant.ypzc_zcctz)){
            // 注册处通知
            Result result = busService.sendSmsToYpzcCs(sqsxid, fileId, wjjl);// 短信
            String msg = new String();
            if (!result.isSuccess()){
                msg += result.getMessage();
            }

            Result result1 = busService.sendEmailToYpzcCs(sqsxid, fileId, wjjl);// 邮箱
            if (!result1.isSuccess()){
                msg += result.getMessage();
            }
            if (StringUtils.isNotBlank(msg)){
                return HttpResult.error(msg);
            }
        }

        return HttpResult.ok("发送成功");
    }

    /** -------------------------------------------【 发送邮箱 - 功能 】--------------------------------------------------------- */

    /** -------------------------------------------【 初始化文件 - 功能 】--------------------------------------------------------- */

    @Log(title = "初始化申请事项文件记录")
    @ApiOperation(value = "初始化申请事项文件记录")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true),
            @ApiImplicitParam(name = "type",value = "模板类型",required = true),
            @ApiImplicitParam(name = "id",value = "文件模板id",required = true)
    })
    @GetMapping(value = "initWjjl")
    public HttpResult<?> initSqsxWjjl(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid,
                                      @RequestParam(value = "type",defaultValue = "") String type,
                                      @RequestParam(value = "id",defaultValue = "")String wjmbId) {
        if (StringUtils.isBlank(sqsxid)) {
            return HttpResult.error("申请事项参数不能为空！操作失败！");
        }
        if (StringUtils.isBlank(type)) {
            return HttpResult.error("模板类型参数为空！操作失败！");
        }

        if (type.equals(WjmlConstant.xpxcscydh)) { // 选派现场审查员的函
            Result result = busService.initXpxcscydh(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        } else if (type.equals(WjmlConstant.xpxcgcydh)) { // 选派现场观察员的函
            busService.initSqsxGcy(sqsxid);// 初始化观察员


            Result result = busService.initXpxcgcydh(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        } else if (type.equals(WjmlConstant.xzjch)) { // 协助检查函
            busService.initSqsxGcy(sqsxid);// 初始化观察员

            Result result = busService.initXzjch(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.gcysm)) { // 观察员声明
            busService.initSqsxGcy(sqsxid);// 初始化观察员

            Result result = busService.initGcysm(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.qydwjctz)) { // 企业单位检查通知
            Result result = busService.initQydwjctz(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        } else if (type.equals(WjmlConstant.jcfa)) { // 检查方案
            Result result = busService.initJcfa(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        } else if (type.equals(WjmlConstant.wlyctsm)) { // 无利益冲突声明
            Result result = busService.initWlyctsm(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        } else if (type.equals(WjmlConstant.xcjcjcycns)) { // 现场检查检查员承诺书
            Result result = busService.initXcjcjcycns(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        } else if (type.equals(WjmlConstant.xcjcjl)) { // 现场检查纪律
            Result result = busService.initXcjcjl(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        } else if (type.equals(WjmlConstant.xcjchyqdb)) { // 现场检查会议签到表
            Result result = busService.initXcjchyqdb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        } else if (type.equals(WjmlConstant.xcjcbg)) { // 现场检查报告
            Result result = busService.initXcjcbg(sqsxid, type,wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        } else if (type.equals(WjmlConstant.xcjcbl)) { // 现场检查笔录
            Result result = busService.initXcjcbl(sqsxid, type,wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.hzp_xcjcjl)) { // 现场检查结论
            Result result = busService.initHzpXcjcjl(sqsxid, type,wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.zhpdbgs)) { // 综合评定报告书
            Result result = busService.initZhpdbgs(sqsxid, type,wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        } else if (type.equals(WjmlConstant.xcjcqxjlb)){ // 现场检查缺陷记录表
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.xcjcbhgxm)){ // 现场检查不合格项目
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.xcjcqxxmjlb)){ // 现场检查缺陷项目记录表
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (type.equals(WjmlConstant.bgzsxhcb)){ // 报告真实性核查表
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (type.equals(WjmlConstant.jsspbg)){ // 技术审评报告
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (type.equals(WjmlConstant.jsscbg)){ // 技术审查报告
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (type.equals(WjmlConstant.xcjcgg)){ // 现场检查公告
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (type.equals(WjmlConstant.xcjcshj)){ // 现场检查审核件
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (type.equals(WjmlConstant.jsspyjspb)){ // 技术审评意见审批表
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (type.equals(WjmlConstant.bztz)){ // 补充整改通知
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.bztz_YLqx)){ // 补正通知
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (type.equals(WjmlConstant.hstz)){ // 函审通知
            Result result = busService.initHstz(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (type.equals(WjmlConstant.qytzs)){ // 企业通知书

            Result result = busService.initQydwjctz(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.ypzc_fhdwtz)){ // 复核单位通知
            Result result = busService.initYpzcFhdwtz(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.ypzc_zcctz)){ // 注册处通知
            Result result = busService.initYpzcFhdwtz(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.zjspyj)){ // 专家审评意见
            Result result = busService.initZjspyj(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.ypzc_zxzhspyj)){ // 中心综合审评意见
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.spfa)){ // 审评方案
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.yshmb)){ // 移送函模板
            Result result = busService.initYshmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.ypzc_cyd)){ // 抽样单
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.ypzc_cyfq)){ // 抽样封签
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.zjqdb)){ // 专家签到表
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.jczgclyq)){ // 检查整改材料要求
            Result result = busService.initJczgclyq(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.zgtzs)){ // 整改通知书
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.zgqrbgs)){ // 整改确认报告书
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }
        else if (type.equals(WjmlConstant.ljzlmyddcb)){ // 廉洁自律和满意度调查表
            Result result = busService.initLjzlfkb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else if (type.equals(WjmlConstant.ljzlfk)) { // 廉洁自律反馈表
            Result result = busService.initLjzlfkb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        } else if (type.equals(WjmlConstant.khmyddc)){ // 客户满意度调查表
            Result result = busService.initLjzlfkb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }else {
            Result result = busService.initCommonSqsxWjmb(sqsxid, type, wjmbId); // 初始化文件记录
            if (!result.isSuccess()) {
                return HttpResult.error(result.getMessage());
            }
        }

        HttpResult<Object> result = new HttpResult<>(true);
        result.setMessage("初始化文件成功");
        return result;
    }

    @Log(title = "获取申请事项-文件目录")
    @ApiOperation(value = "获取申请事项-文件目录")
    @GetMapping(value = "querySqsxWjmlFileList")
    public HttpResult<?> querySqsxWjmlFileList(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数丢失，请联系管理员!");
        }

        List<Map> mapList = spcyBlgcclService.queryBlgcclMlList(sqsxid);
        return HttpResult.ok(mapList);
    }

    @Log(title = "获取企业申请材料文件记录")
    @ApiOperation(value = "获取企业申请材料文件记录")
    @ApiImplicitParam(value = "sqsxid",name = "申请事项id",required = true)
    @GetMapping(value = "queryQySqclWjjlList")
    public HttpResult<?> queryQySqclWjjlList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空！操作失败！");
        }
        List<SpcySqsxWjjl> wjjlList = spcySqsxWjjlService.list(new LambdaQueryWrapper<SpcySqsxWjjl>()
                .eq(SpcySqsxWjjl::getFpid,sqsxid));
        return HttpResult.ok(wjjlList);
    }

    @Log(title = "申请事项-重新选择模板")
    @ApiOperation(value = "申请事项-重新选择模板")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true),
            @ApiImplicitParam(name = "fileid",value = "文件记录id",required = true),
            @ApiImplicitParam(name = "id",value = "文件模板id",required = true),
    })
    @GetMapping(value = "selectWjmb")
    public HttpResult<?> selectWjmb(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid,
                                    @RequestParam(value = "fileid",defaultValue = "") String fileid,
                                    @RequestParam(value = "id",defaultValue = "")String wjmbid){

        Result result = busService.sqsxWjjlReloadWjmb(sqsxid, fileid, wjmbid);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("操作成功");
    }


    @Log(title = "字符串套用模板")
    @ApiOperation(value = "字符串套用模板")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id"),
            @ApiImplicitParam(name = "fywflcode",value = "业务分类编码"),
            @ApiImplicitParam(name = "content",value = "替换的内容")
    })
    @PostMapping(value = "replaceStringMb")
    public HttpResult replaceStringMb(@RequestBody Map<String,String> paramMap){
        String sqsxid = paramMap.get("sqsxid");
        String fywflcode = paramMap.get("fywflcode");
        String content = paramMap.get("content");

        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空！");
        }
        if (StringUtils.isBlank(fywflcode)){
            return HttpResult.error("业务分类参数为空！");
        }
        Map<String,String> map = busService.getObjectMap(sqsxid,null);
        if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPZC) || fywflcode.equals(SpcyConstant.YWFL_CODE_YPZCLC)){

        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPSC)){
            map.putAll(busService.mbFieldQkhzByYplt(sqsxid));
            map.putAll(busService.mbFieldCommonByYplt(sqsxid, null));

        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPJY)){
            map.putAll(busService.mbFieldByYplt(sqsxid));

        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YLQX)){

        }else if (fywflcode.equals(SpcyConstant.YWFL_CODE_HZP)){
            map.putAll(busService.mbFieldCommonByHzp(sqsxid));
            map.putAll(busService.mdFieldXcjcblByHzp(sqsxid));

        }

        if (StringUtils.isNotBlank(content)) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                content = content.replace(entry.getKey(), entry.getValue());
            }
        }

        Map resultMap = new HashMap();
        resultMap.put("content",content);
        return HttpResult.ok(resultMap);
    }

    /*****************************************************【合并pdf】******************************************************/
//    @Log(title = "下载合并PDF文件-申请事项")
//    @ApiOperation(value = "下载合并PDF文件-申请事项")
//    @GetMapping(value = "downloadMergePdf")
    public void hbpdf(@RequestParam("sqsxid")String sqsxid, HttpServletResponse response){
        if (StringUtils.isBlank(sqsxid)){
            log.error("申请事项id为空");
            return;
        }
        List<SpcySqsxWjjl> pdfWjjlList = spcySqsxWjjlService.list(new LambdaQueryWrapper<SpcySqsxWjjl>()
                .eq(SpcySqsxWjjl::getFpid, sqsxid)
                .eq(SpcySqsxWjjl::getFwjlx, ".pdf")
                .orderByDesc(SpcySqsxWjjl::getCreateTime)
                .orderByAsc(SpcySqsxWjjl::getFwjlx1));
        if (CollectionUtils.isNotEmpty(pdfWjjlList)){
            List<String> sourceFilePaths = new ArrayList<>();
            List<String> fileNames = new ArrayList<>();
            for (SpcySqsxWjjl wjjl : pdfWjjlList){
                fileNames.add(wjjl.getFwjxsmc());
                sourceFilePaths.add(localFileUploadUtils.getSqsxWjjlAbsUrl(wjjl.getFcflj()));
            }

            String pdfMc = "";

//            PdfUtils.mergePdf(sourceFilePaths,outurl); // 合并pdf文件

            /** pdf转图片 ,图片转pdf */
            List<String> pdfurl2 = new ArrayList<>();
            for (String outurl : sourceFilePaths) {
                List<String> imgUrlList = PdfUtils.pdf2Image(outurl, 200);

                int i = 1;
                if (CollectionUtils.isNotEmpty(imgUrlList)) {
                    for (String imgUrl : imgUrlList) {

                        String outurl2 = localFileUploadUtils.getSqsxWjjlAbsUrl("/" + i + "tpimg_" + GetUuIdUtils.NotReplaceUuId() + ".pdf");
                        pdfurl2.add(PdfUtils.img2Pdf(imgUrl, outurl2));
                        i++;
                        PdfUtils.deleteByCompleteUrl(imgUrl);
                    }
                }
            }

            pdfMc = "mergePdf-"+GetUuIdUtils.NotReplaceUuId()+".pdf";

            String outurl3 = localFileUploadUtils.getSqsxWjjlAbsUrl("/"+pdfMc);
            PdfUtils.mergePdf(pdfurl2,outurl3); // 合并pdf文件
            if (CollectionUtil.isNotEmpty(pdfurl2)) {
                for (String delUrl : pdfurl2) {
                    PdfUtils.deleteByCompleteUrl(delUrl);
                }
            }

            Map<String, Object> catalogs = PdfUtils.getPdfMl(sourceFilePaths,fileNames); // 获取目录

            int catalogPdfPageSize = 2;
            String outUrl = "ml-"+GetUuIdUtils.NotReplaceUuId()+".pdf";

            String outwjPdf = localFileUploadUtils.getSqsxWjjlAbsUrl("/"+outUrl);
            try {
                // 生成带目录的pdf文件
//                PdfUtils.createPdfWithCatalog(outurl, outwjPdf, "合并PDF文件目录", catalogs, catalogPdfPageSize);
                PdfUtils.createPdfWithCatalog(outurl3, outwjPdf, "PDF文件目录", catalogs, catalogPdfPageSize);
            } catch (IOException e) {
                log.error("生成目录失败：{}",e.getMessage());
            }
            localFileUploadUtils.deleteLocalFileUrl("/"+pdfMc); // 删除合并的pdf文件
            localFileUploadUtils.ejzLocalFileURl("/"+outUrl,response);
//            localFileUploadUtils.deleteLocalFileUrl("/"+outUrl); // 删除合并目录的pdf文件
        }

    }

    //    @Log(title = "初始化申请事项的文件目录记录")
//    @ApiOperation(value = "初始化申请事项的文件目录记录")
//    @GetMapping(value = "initSqsxWjmljl")
    public HttpResult<?> initSqsxWjmljl(@RequestParam("sqsxid") String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("主要参数丢失，请联系管理员");
        }
        String ywflCode = busService.getYwflCode(sqsxid);
        String nowNodeName = busService.getNowNodeName(sqsxid);
        List<SqsxWjmljlVo> sqsxWjmljlVoList = new ArrayList<>(); // 申请事项-文件目录记录

        // 当前申请事项-业务的文件目录
        List<SpcySqsxWjml> wjmlList = spcySqsxWjmlService.list(new LambdaQueryWrapper<SpcySqsxWjml>()
                .eq(SpcySqsxWjml::getFwjlx1, WjmlConstant.wjml_type_1_xcjccl)
                .eq(StringUtils.isNotBlank(ywflCode), SpcySqsxWjml::getFywflcode, ywflCode)
                .orderByAsc(SpcySqsxWjml::getForder));
        if (CollectionUtils.isNotEmpty(wjmlList)) {

            List<SpcySqsxWjmljl> isExistWjmljl = spcySqsxWjmljlService.list(new LambdaQueryWrapper<SpcySqsxWjmljl>()
                    .eq(SpcySqsxWjmljl::getFsqsxid, sqsxid));
            // 初始化申请事项-文件目录
            if (CollectionUtils.isEmpty(isExistWjmljl)) {
                List<SpcySqsxWjmljl> wjmljlList = new ArrayList<>();
                SpcySqsxWjmljl wjmljl = null;
                String logNr = "生成文件目录文件: ";

                for (SpcySqsxWjml wjml : wjmlList) {
                    wjmljl = new SpcySqsxWjmljl();
                    BeanUtil.copyProperties(wjml, wjmljl);
                    wjmljl.setId(GetUuIdUtils.ReplaceUuId());
                    wjmljl.setFsqsxid(sqsxid);
                    wjmljlList.add(wjmljl);

                    logNr += ObjectToMapUtils.objectToMap(wjmljl); // 日志
                }
                if (CollectionUtils.isNotEmpty(wjmljlList)) {
                    spcySqsxWjmljlService.saveBatch(wjmljlList);
                    spcyLogService.addLogs(nowNodeName, logNr, sqsxid, LogConstant.LOGS_SQSX_WJMLJL, SpcyConstant.LOGS_SYS_TYPE_XZ);
                }
            }

            // 当前申请事项的文件目录
            List<SpcySqsxWjmljl> sqsxWjmljls = spcySqsxWjmljlService.list(new LambdaQueryWrapper<SpcySqsxWjmljl>()
                    .eq(SpcySqsxWjmljl::getFwjlx1, WjmlConstant.wjml_type_1_xcjccl)
                    .eq(SpcySqsxWjmljl::getFsqsxid, sqsxid)
                    .orderByAsc(SpcySqsxWjmljl::getForder));
            if (CollectionUtils.isNotEmpty(sqsxWjmljls)){
                SqsxWjmljlVo sqsxWjmljlVo = null;
                for (SpcySqsxWjmljl wjmljl1 : sqsxWjmljls){
                    sqsxWjmljlVo = new SqsxWjmljlVo();
                    List<SpcySqsxWjjl> wjjlList = spcySqsxWjjlService.list(new LambdaQueryWrapper<SpcySqsxWjjl>()
                            .eq(StringUtils.isNotBlank(wjmljl1.getFlxmc()), SpcySqsxWjjl::getFwjlx1, wjmljl1.getFlxmc())
                            .eq(SpcySqsxWjjl::getFpid,sqsxid));
                    sqsxWjmljlVo.setFlxmc(wjmljl1.getFlxmc());
                    sqsxWjmljlVo.setForder(wjmljl1.getForder());
                    sqsxWjmljlVo.setFbz(wjjlList.size()+"份");
                    sqsxWjmljlVo.setWjjlList(wjjlList);
                    sqsxWjmljlVoList.add(sqsxWjmljlVo);
                }
            }
        }

        return HttpResult.ok(sqsxWjmljlVoList);
    }

    /*@Log(title = "下载pdf文件压缩包-申请事项")
    @ApiOperation(value = "下载pdf文件压缩包-申请事项")*/
    @GetMapping(value = "downloadZipPdf")
    public void downloadZipPdf(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid,HttpServletResponse response){
        if (StringUtils.isBlank(sqsxid)){
            log.error("下载pdf文件压缩包-申请事项失败！申请事项id为空！");
            return;
        }

        List<File> files = new ArrayList<>();
        List<String> fileNames = new ArrayList<>();
        List<SpcySqsxWjjl> pdfWjjlList = spcySqsxWjjlService.list(new LambdaQueryWrapper<SpcySqsxWjjl>()
                .eq(SpcySqsxWjjl::getFpid, sqsxid)
                .orderByDesc(SpcySqsxWjjl::getCreateTime)
                .orderByAsc(SpcySqsxWjjl::getFwjlx1));
        if (CollectionUtils.isNotEmpty(pdfWjjlList)){
            for (SpcySqsxWjjl wjjl : pdfWjjlList){
                if (StringUtils.isNotBlank(wjjl.getFcflj())) {
                    fileNames.add(wjjl.getFwjxsmc()+wjjl.getFwjlx());
                    files.add(new File(localFileUploadUtils.getSqsxWjjlAbsUrl(wjjl.getFcflj())));
                }
            }
        }

        PdfUtils.downZip(files,fileNames,response);
    }


    /*@Log(title = "获取发送下环节待办短信内容")
    @ApiOperation(value = "获取发送下环节待办短信内容")*/
    @GetMapping(value = "getNextNodeSmsContent")
    public HttpResult getNextNodeSmsContent(@RequestParam(value = "jobid",defaultValue = "")String jobid){

        HttpResult result = new HttpResult(true);
        result.setMessage("操作成功");
        result.setResult(busService.getNextNodeSmsContent(null, jobid));
        return result;
    }


}
